
_echo:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include "stat.h"
#include "user.h"

int
main(int argc, char *argv[])
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 20             	sub    $0x20,%esp
  int i;

  for(i = 1; i < argc; i++)
   9:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
  10:	00 
  11:	eb 4b                	jmp    5e <main+0x5e>
    printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
  13:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  17:	83 c0 01             	add    $0x1,%eax
  1a:	3b 45 08             	cmp    0x8(%ebp),%eax
  1d:	7d 07                	jge    26 <main+0x26>
  1f:	b8 c2 0e 00 00       	mov    $0xec2,%eax
  24:	eb 05                	jmp    2b <main+0x2b>
  26:	b8 c4 0e 00 00       	mov    $0xec4,%eax
  2b:	8b 54 24 1c          	mov    0x1c(%esp),%edx
  2f:	8d 0c 95 00 00 00 00 	lea    0x0(,%edx,4),%ecx
  36:	8b 55 0c             	mov    0xc(%ebp),%edx
  39:	01 ca                	add    %ecx,%edx
  3b:	8b 12                	mov    (%edx),%edx
  3d:	89 44 24 0c          	mov    %eax,0xc(%esp)
  41:	89 54 24 08          	mov    %edx,0x8(%esp)
  45:	c7 44 24 04 c6 0e 00 	movl   $0xec6,0x4(%esp)
  4c:	00 
  4d:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  54:	e8 18 04 00 00       	call   471 <printf>
int
main(int argc, char *argv[])
{
  int i;

  for(i = 1; i < argc; i++)
  59:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
  5e:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  62:	3b 45 08             	cmp    0x8(%ebp),%eax
  65:	7c ac                	jl     13 <main+0x13>
    printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
  exit();
  67:	e8 68 02 00 00       	call   2d4 <exit>

0000006c <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
  6c:	55                   	push   %ebp
  6d:	89 e5                	mov    %esp,%ebp
  6f:	57                   	push   %edi
  70:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
  71:	8b 4d 08             	mov    0x8(%ebp),%ecx
  74:	8b 55 10             	mov    0x10(%ebp),%edx
  77:	8b 45 0c             	mov    0xc(%ebp),%eax
  7a:	89 cb                	mov    %ecx,%ebx
  7c:	89 df                	mov    %ebx,%edi
  7e:	89 d1                	mov    %edx,%ecx
  80:	fc                   	cld    
  81:	f3 aa                	rep stos %al,%es:(%edi)
  83:	89 ca                	mov    %ecx,%edx
  85:	89 fb                	mov    %edi,%ebx
  87:	89 5d 08             	mov    %ebx,0x8(%ebp)
  8a:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
  8d:	5b                   	pop    %ebx
  8e:	5f                   	pop    %edi
  8f:	5d                   	pop    %ebp
  90:	c3                   	ret    

00000091 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
  91:	55                   	push   %ebp
  92:	89 e5                	mov    %esp,%ebp
  94:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
  97:	8b 45 08             	mov    0x8(%ebp),%eax
  9a:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
  9d:	90                   	nop
  9e:	8b 45 0c             	mov    0xc(%ebp),%eax
  a1:	0f b6 10             	movzbl (%eax),%edx
  a4:	8b 45 08             	mov    0x8(%ebp),%eax
  a7:	88 10                	mov    %dl,(%eax)
  a9:	8b 45 08             	mov    0x8(%ebp),%eax
  ac:	0f b6 00             	movzbl (%eax),%eax
  af:	84 c0                	test   %al,%al
  b1:	0f 95 c0             	setne  %al
  b4:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  b8:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
  bc:	84 c0                	test   %al,%al
  be:	75 de                	jne    9e <strcpy+0xd>
    ;
  return os;
  c0:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  c3:	c9                   	leave  
  c4:	c3                   	ret    

000000c5 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  c5:	55                   	push   %ebp
  c6:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
  c8:	eb 08                	jmp    d2 <strcmp+0xd>
    p++, q++;
  ca:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  ce:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
  d2:	8b 45 08             	mov    0x8(%ebp),%eax
  d5:	0f b6 00             	movzbl (%eax),%eax
  d8:	84 c0                	test   %al,%al
  da:	74 10                	je     ec <strcmp+0x27>
  dc:	8b 45 08             	mov    0x8(%ebp),%eax
  df:	0f b6 10             	movzbl (%eax),%edx
  e2:	8b 45 0c             	mov    0xc(%ebp),%eax
  e5:	0f b6 00             	movzbl (%eax),%eax
  e8:	38 c2                	cmp    %al,%dl
  ea:	74 de                	je     ca <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
  ec:	8b 45 08             	mov    0x8(%ebp),%eax
  ef:	0f b6 00             	movzbl (%eax),%eax
  f2:	0f b6 d0             	movzbl %al,%edx
  f5:	8b 45 0c             	mov    0xc(%ebp),%eax
  f8:	0f b6 00             	movzbl (%eax),%eax
  fb:	0f b6 c0             	movzbl %al,%eax
  fe:	89 d1                	mov    %edx,%ecx
 100:	29 c1                	sub    %eax,%ecx
 102:	89 c8                	mov    %ecx,%eax
}
 104:	5d                   	pop    %ebp
 105:	c3                   	ret    

00000106 <strlen>:

uint
strlen(char *s)
{
 106:	55                   	push   %ebp
 107:	89 e5                	mov    %esp,%ebp
 109:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 10c:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 113:	eb 04                	jmp    119 <strlen+0x13>
 115:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 119:	8b 55 fc             	mov    -0x4(%ebp),%edx
 11c:	8b 45 08             	mov    0x8(%ebp),%eax
 11f:	01 d0                	add    %edx,%eax
 121:	0f b6 00             	movzbl (%eax),%eax
 124:	84 c0                	test   %al,%al
 126:	75 ed                	jne    115 <strlen+0xf>
    ;
  return n;
 128:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 12b:	c9                   	leave  
 12c:	c3                   	ret    

0000012d <memset>:

void*
memset(void *dst, int c, uint n)
{
 12d:	55                   	push   %ebp
 12e:	89 e5                	mov    %esp,%ebp
 130:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 133:	8b 45 10             	mov    0x10(%ebp),%eax
 136:	89 44 24 08          	mov    %eax,0x8(%esp)
 13a:	8b 45 0c             	mov    0xc(%ebp),%eax
 13d:	89 44 24 04          	mov    %eax,0x4(%esp)
 141:	8b 45 08             	mov    0x8(%ebp),%eax
 144:	89 04 24             	mov    %eax,(%esp)
 147:	e8 20 ff ff ff       	call   6c <stosb>
  return dst;
 14c:	8b 45 08             	mov    0x8(%ebp),%eax
}
 14f:	c9                   	leave  
 150:	c3                   	ret    

00000151 <strchr>:

char*
strchr(const char *s, char c)
{
 151:	55                   	push   %ebp
 152:	89 e5                	mov    %esp,%ebp
 154:	83 ec 04             	sub    $0x4,%esp
 157:	8b 45 0c             	mov    0xc(%ebp),%eax
 15a:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 15d:	eb 14                	jmp    173 <strchr+0x22>
    if(*s == c)
 15f:	8b 45 08             	mov    0x8(%ebp),%eax
 162:	0f b6 00             	movzbl (%eax),%eax
 165:	3a 45 fc             	cmp    -0x4(%ebp),%al
 168:	75 05                	jne    16f <strchr+0x1e>
      return (char*)s;
 16a:	8b 45 08             	mov    0x8(%ebp),%eax
 16d:	eb 13                	jmp    182 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 16f:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 173:	8b 45 08             	mov    0x8(%ebp),%eax
 176:	0f b6 00             	movzbl (%eax),%eax
 179:	84 c0                	test   %al,%al
 17b:	75 e2                	jne    15f <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 17d:	b8 00 00 00 00       	mov    $0x0,%eax
}
 182:	c9                   	leave  
 183:	c3                   	ret    

00000184 <gets>:

char*
gets(char *buf, int max)
{
 184:	55                   	push   %ebp
 185:	89 e5                	mov    %esp,%ebp
 187:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 18a:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 191:	eb 46                	jmp    1d9 <gets+0x55>
    cc = read(0, &c, 1);
 193:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 19a:	00 
 19b:	8d 45 ef             	lea    -0x11(%ebp),%eax
 19e:	89 44 24 04          	mov    %eax,0x4(%esp)
 1a2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 1a9:	e8 3e 01 00 00       	call   2ec <read>
 1ae:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 1b1:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 1b5:	7e 2f                	jle    1e6 <gets+0x62>
      break;
    buf[i++] = c;
 1b7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1ba:	8b 45 08             	mov    0x8(%ebp),%eax
 1bd:	01 c2                	add    %eax,%edx
 1bf:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1c3:	88 02                	mov    %al,(%edx)
 1c5:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 1c9:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1cd:	3c 0a                	cmp    $0xa,%al
 1cf:	74 16                	je     1e7 <gets+0x63>
 1d1:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1d5:	3c 0d                	cmp    $0xd,%al
 1d7:	74 0e                	je     1e7 <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 1d9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 1dc:	83 c0 01             	add    $0x1,%eax
 1df:	3b 45 0c             	cmp    0xc(%ebp),%eax
 1e2:	7c af                	jl     193 <gets+0xf>
 1e4:	eb 01                	jmp    1e7 <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 1e6:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 1e7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1ea:	8b 45 08             	mov    0x8(%ebp),%eax
 1ed:	01 d0                	add    %edx,%eax
 1ef:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 1f2:	8b 45 08             	mov    0x8(%ebp),%eax
}
 1f5:	c9                   	leave  
 1f6:	c3                   	ret    

000001f7 <stat>:

int
stat(char *n, struct stat *st)
{
 1f7:	55                   	push   %ebp
 1f8:	89 e5                	mov    %esp,%ebp
 1fa:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 1fd:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 204:	00 
 205:	8b 45 08             	mov    0x8(%ebp),%eax
 208:	89 04 24             	mov    %eax,(%esp)
 20b:	e8 04 01 00 00       	call   314 <open>
 210:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 213:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 217:	79 07                	jns    220 <stat+0x29>
    return -1;
 219:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 21e:	eb 23                	jmp    243 <stat+0x4c>
  r = fstat(fd, st);
 220:	8b 45 0c             	mov    0xc(%ebp),%eax
 223:	89 44 24 04          	mov    %eax,0x4(%esp)
 227:	8b 45 f4             	mov    -0xc(%ebp),%eax
 22a:	89 04 24             	mov    %eax,(%esp)
 22d:	e8 fa 00 00 00       	call   32c <fstat>
 232:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 235:	8b 45 f4             	mov    -0xc(%ebp),%eax
 238:	89 04 24             	mov    %eax,(%esp)
 23b:	e8 bc 00 00 00       	call   2fc <close>
  return r;
 240:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 243:	c9                   	leave  
 244:	c3                   	ret    

00000245 <atoi>:

int
atoi(const char *s)
{
 245:	55                   	push   %ebp
 246:	89 e5                	mov    %esp,%ebp
 248:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 24b:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 252:	eb 23                	jmp    277 <atoi+0x32>
    n = n*10 + *s++ - '0';
 254:	8b 55 fc             	mov    -0x4(%ebp),%edx
 257:	89 d0                	mov    %edx,%eax
 259:	c1 e0 02             	shl    $0x2,%eax
 25c:	01 d0                	add    %edx,%eax
 25e:	01 c0                	add    %eax,%eax
 260:	89 c2                	mov    %eax,%edx
 262:	8b 45 08             	mov    0x8(%ebp),%eax
 265:	0f b6 00             	movzbl (%eax),%eax
 268:	0f be c0             	movsbl %al,%eax
 26b:	01 d0                	add    %edx,%eax
 26d:	83 e8 30             	sub    $0x30,%eax
 270:	89 45 fc             	mov    %eax,-0x4(%ebp)
 273:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 277:	8b 45 08             	mov    0x8(%ebp),%eax
 27a:	0f b6 00             	movzbl (%eax),%eax
 27d:	3c 2f                	cmp    $0x2f,%al
 27f:	7e 0a                	jle    28b <atoi+0x46>
 281:	8b 45 08             	mov    0x8(%ebp),%eax
 284:	0f b6 00             	movzbl (%eax),%eax
 287:	3c 39                	cmp    $0x39,%al
 289:	7e c9                	jle    254 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 28b:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 28e:	c9                   	leave  
 28f:	c3                   	ret    

00000290 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 290:	55                   	push   %ebp
 291:	89 e5                	mov    %esp,%ebp
 293:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 296:	8b 45 08             	mov    0x8(%ebp),%eax
 299:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 29c:	8b 45 0c             	mov    0xc(%ebp),%eax
 29f:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 2a2:	eb 13                	jmp    2b7 <memmove+0x27>
    *dst++ = *src++;
 2a4:	8b 45 f8             	mov    -0x8(%ebp),%eax
 2a7:	0f b6 10             	movzbl (%eax),%edx
 2aa:	8b 45 fc             	mov    -0x4(%ebp),%eax
 2ad:	88 10                	mov    %dl,(%eax)
 2af:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 2b3:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 2b7:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 2bb:	0f 9f c0             	setg   %al
 2be:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 2c2:	84 c0                	test   %al,%al
 2c4:	75 de                	jne    2a4 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 2c6:	8b 45 08             	mov    0x8(%ebp),%eax
}
 2c9:	c9                   	leave  
 2ca:	c3                   	ret    
 2cb:	90                   	nop

000002cc <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 2cc:	b8 01 00 00 00       	mov    $0x1,%eax
 2d1:	cd 40                	int    $0x40
 2d3:	c3                   	ret    

000002d4 <exit>:
SYSCALL(exit)
 2d4:	b8 02 00 00 00       	mov    $0x2,%eax
 2d9:	cd 40                	int    $0x40
 2db:	c3                   	ret    

000002dc <wait>:
SYSCALL(wait)
 2dc:	b8 03 00 00 00       	mov    $0x3,%eax
 2e1:	cd 40                	int    $0x40
 2e3:	c3                   	ret    

000002e4 <pipe>:
SYSCALL(pipe)
 2e4:	b8 04 00 00 00       	mov    $0x4,%eax
 2e9:	cd 40                	int    $0x40
 2eb:	c3                   	ret    

000002ec <read>:
SYSCALL(read)
 2ec:	b8 05 00 00 00       	mov    $0x5,%eax
 2f1:	cd 40                	int    $0x40
 2f3:	c3                   	ret    

000002f4 <write>:
SYSCALL(write)
 2f4:	b8 10 00 00 00       	mov    $0x10,%eax
 2f9:	cd 40                	int    $0x40
 2fb:	c3                   	ret    

000002fc <close>:
SYSCALL(close)
 2fc:	b8 15 00 00 00       	mov    $0x15,%eax
 301:	cd 40                	int    $0x40
 303:	c3                   	ret    

00000304 <kill>:
SYSCALL(kill)
 304:	b8 06 00 00 00       	mov    $0x6,%eax
 309:	cd 40                	int    $0x40
 30b:	c3                   	ret    

0000030c <exec>:
SYSCALL(exec)
 30c:	b8 07 00 00 00       	mov    $0x7,%eax
 311:	cd 40                	int    $0x40
 313:	c3                   	ret    

00000314 <open>:
SYSCALL(open)
 314:	b8 0f 00 00 00       	mov    $0xf,%eax
 319:	cd 40                	int    $0x40
 31b:	c3                   	ret    

0000031c <mknod>:
SYSCALL(mknod)
 31c:	b8 11 00 00 00       	mov    $0x11,%eax
 321:	cd 40                	int    $0x40
 323:	c3                   	ret    

00000324 <unlink>:
SYSCALL(unlink)
 324:	b8 12 00 00 00       	mov    $0x12,%eax
 329:	cd 40                	int    $0x40
 32b:	c3                   	ret    

0000032c <fstat>:
SYSCALL(fstat)
 32c:	b8 08 00 00 00       	mov    $0x8,%eax
 331:	cd 40                	int    $0x40
 333:	c3                   	ret    

00000334 <link>:
SYSCALL(link)
 334:	b8 13 00 00 00       	mov    $0x13,%eax
 339:	cd 40                	int    $0x40
 33b:	c3                   	ret    

0000033c <mkdir>:
SYSCALL(mkdir)
 33c:	b8 14 00 00 00       	mov    $0x14,%eax
 341:	cd 40                	int    $0x40
 343:	c3                   	ret    

00000344 <chdir>:
SYSCALL(chdir)
 344:	b8 09 00 00 00       	mov    $0x9,%eax
 349:	cd 40                	int    $0x40
 34b:	c3                   	ret    

0000034c <dup>:
SYSCALL(dup)
 34c:	b8 0a 00 00 00       	mov    $0xa,%eax
 351:	cd 40                	int    $0x40
 353:	c3                   	ret    

00000354 <getpid>:
SYSCALL(getpid)
 354:	b8 0b 00 00 00       	mov    $0xb,%eax
 359:	cd 40                	int    $0x40
 35b:	c3                   	ret    

0000035c <sbrk>:
SYSCALL(sbrk)
 35c:	b8 0c 00 00 00       	mov    $0xc,%eax
 361:	cd 40                	int    $0x40
 363:	c3                   	ret    

00000364 <sleep>:
SYSCALL(sleep)
 364:	b8 0d 00 00 00       	mov    $0xd,%eax
 369:	cd 40                	int    $0x40
 36b:	c3                   	ret    

0000036c <uptime>:
SYSCALL(uptime)
 36c:	b8 0e 00 00 00       	mov    $0xe,%eax
 371:	cd 40                	int    $0x40
 373:	c3                   	ret    

00000374 <signal>:

//our addition
SYSCALL(signal)
 374:	b8 1f 00 00 00       	mov    $0x1f,%eax
 379:	cd 40                	int    $0x40
 37b:	c3                   	ret    

0000037c <sigsend>:
SYSCALL(sigsend)
 37c:	b8 20 00 00 00       	mov    $0x20,%eax
 381:	cd 40                	int    $0x40
 383:	c3                   	ret    

00000384 <alarm>:
SYSCALL(alarm)
 384:	b8 21 00 00 00       	mov    $0x21,%eax
 389:	cd 40                	int    $0x40
 38b:	c3                   	ret    

0000038c <getTicks>:
SYSCALL(getTicks)
 38c:	b8 22 00 00 00       	mov    $0x22,%eax
 391:	cd 40                	int    $0x40
 393:	c3                   	ret    

00000394 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 394:	55                   	push   %ebp
 395:	89 e5                	mov    %esp,%ebp
 397:	83 ec 28             	sub    $0x28,%esp
 39a:	8b 45 0c             	mov    0xc(%ebp),%eax
 39d:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 3a0:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 3a7:	00 
 3a8:	8d 45 f4             	lea    -0xc(%ebp),%eax
 3ab:	89 44 24 04          	mov    %eax,0x4(%esp)
 3af:	8b 45 08             	mov    0x8(%ebp),%eax
 3b2:	89 04 24             	mov    %eax,(%esp)
 3b5:	e8 3a ff ff ff       	call   2f4 <write>
}
 3ba:	c9                   	leave  
 3bb:	c3                   	ret    

000003bc <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 3bc:	55                   	push   %ebp
 3bd:	89 e5                	mov    %esp,%ebp
 3bf:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 3c2:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 3c9:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 3cd:	74 17                	je     3e6 <printint+0x2a>
 3cf:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 3d3:	79 11                	jns    3e6 <printint+0x2a>
    neg = 1;
 3d5:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 3dc:	8b 45 0c             	mov    0xc(%ebp),%eax
 3df:	f7 d8                	neg    %eax
 3e1:	89 45 ec             	mov    %eax,-0x14(%ebp)
 3e4:	eb 06                	jmp    3ec <printint+0x30>
  } else {
    x = xx;
 3e6:	8b 45 0c             	mov    0xc(%ebp),%eax
 3e9:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 3ec:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 3f3:	8b 4d 10             	mov    0x10(%ebp),%ecx
 3f6:	8b 45 ec             	mov    -0x14(%ebp),%eax
 3f9:	ba 00 00 00 00       	mov    $0x0,%edx
 3fe:	f7 f1                	div    %ecx
 400:	89 d0                	mov    %edx,%eax
 402:	0f b6 80 28 13 00 00 	movzbl 0x1328(%eax),%eax
 409:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 40c:	8b 55 f4             	mov    -0xc(%ebp),%edx
 40f:	01 ca                	add    %ecx,%edx
 411:	88 02                	mov    %al,(%edx)
 413:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 417:	8b 55 10             	mov    0x10(%ebp),%edx
 41a:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 41d:	8b 45 ec             	mov    -0x14(%ebp),%eax
 420:	ba 00 00 00 00       	mov    $0x0,%edx
 425:	f7 75 d4             	divl   -0x2c(%ebp)
 428:	89 45 ec             	mov    %eax,-0x14(%ebp)
 42b:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 42f:	75 c2                	jne    3f3 <printint+0x37>
  if(neg)
 431:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 435:	74 2e                	je     465 <printint+0xa9>
    buf[i++] = '-';
 437:	8d 55 dc             	lea    -0x24(%ebp),%edx
 43a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 43d:	01 d0                	add    %edx,%eax
 43f:	c6 00 2d             	movb   $0x2d,(%eax)
 442:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 446:	eb 1d                	jmp    465 <printint+0xa9>
    putc(fd, buf[i]);
 448:	8d 55 dc             	lea    -0x24(%ebp),%edx
 44b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 44e:	01 d0                	add    %edx,%eax
 450:	0f b6 00             	movzbl (%eax),%eax
 453:	0f be c0             	movsbl %al,%eax
 456:	89 44 24 04          	mov    %eax,0x4(%esp)
 45a:	8b 45 08             	mov    0x8(%ebp),%eax
 45d:	89 04 24             	mov    %eax,(%esp)
 460:	e8 2f ff ff ff       	call   394 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 465:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 469:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 46d:	79 d9                	jns    448 <printint+0x8c>
    putc(fd, buf[i]);
}
 46f:	c9                   	leave  
 470:	c3                   	ret    

00000471 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 471:	55                   	push   %ebp
 472:	89 e5                	mov    %esp,%ebp
 474:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 477:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 47e:	8d 45 0c             	lea    0xc(%ebp),%eax
 481:	83 c0 04             	add    $0x4,%eax
 484:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 487:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 48e:	e9 7d 01 00 00       	jmp    610 <printf+0x19f>
    c = fmt[i] & 0xff;
 493:	8b 55 0c             	mov    0xc(%ebp),%edx
 496:	8b 45 f0             	mov    -0x10(%ebp),%eax
 499:	01 d0                	add    %edx,%eax
 49b:	0f b6 00             	movzbl (%eax),%eax
 49e:	0f be c0             	movsbl %al,%eax
 4a1:	25 ff 00 00 00       	and    $0xff,%eax
 4a6:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 4a9:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4ad:	75 2c                	jne    4db <printf+0x6a>
      if(c == '%'){
 4af:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 4b3:	75 0c                	jne    4c1 <printf+0x50>
        state = '%';
 4b5:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 4bc:	e9 4b 01 00 00       	jmp    60c <printf+0x19b>
      } else {
        putc(fd, c);
 4c1:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 4c4:	0f be c0             	movsbl %al,%eax
 4c7:	89 44 24 04          	mov    %eax,0x4(%esp)
 4cb:	8b 45 08             	mov    0x8(%ebp),%eax
 4ce:	89 04 24             	mov    %eax,(%esp)
 4d1:	e8 be fe ff ff       	call   394 <putc>
 4d6:	e9 31 01 00 00       	jmp    60c <printf+0x19b>
      }
    } else if(state == '%'){
 4db:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 4df:	0f 85 27 01 00 00    	jne    60c <printf+0x19b>
      if(c == 'd'){
 4e5:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 4e9:	75 2d                	jne    518 <printf+0xa7>
        printint(fd, *ap, 10, 1);
 4eb:	8b 45 e8             	mov    -0x18(%ebp),%eax
 4ee:	8b 00                	mov    (%eax),%eax
 4f0:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 4f7:	00 
 4f8:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 4ff:	00 
 500:	89 44 24 04          	mov    %eax,0x4(%esp)
 504:	8b 45 08             	mov    0x8(%ebp),%eax
 507:	89 04 24             	mov    %eax,(%esp)
 50a:	e8 ad fe ff ff       	call   3bc <printint>
        ap++;
 50f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 513:	e9 ed 00 00 00       	jmp    605 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 518:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 51c:	74 06                	je     524 <printf+0xb3>
 51e:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 522:	75 2d                	jne    551 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 524:	8b 45 e8             	mov    -0x18(%ebp),%eax
 527:	8b 00                	mov    (%eax),%eax
 529:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 530:	00 
 531:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 538:	00 
 539:	89 44 24 04          	mov    %eax,0x4(%esp)
 53d:	8b 45 08             	mov    0x8(%ebp),%eax
 540:	89 04 24             	mov    %eax,(%esp)
 543:	e8 74 fe ff ff       	call   3bc <printint>
        ap++;
 548:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 54c:	e9 b4 00 00 00       	jmp    605 <printf+0x194>
      } else if(c == 's'){
 551:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 555:	75 46                	jne    59d <printf+0x12c>
        s = (char*)*ap;
 557:	8b 45 e8             	mov    -0x18(%ebp),%eax
 55a:	8b 00                	mov    (%eax),%eax
 55c:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 55f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 563:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 567:	75 27                	jne    590 <printf+0x11f>
          s = "(null)";
 569:	c7 45 f4 cb 0e 00 00 	movl   $0xecb,-0xc(%ebp)
        while(*s != 0){
 570:	eb 1e                	jmp    590 <printf+0x11f>
          putc(fd, *s);
 572:	8b 45 f4             	mov    -0xc(%ebp),%eax
 575:	0f b6 00             	movzbl (%eax),%eax
 578:	0f be c0             	movsbl %al,%eax
 57b:	89 44 24 04          	mov    %eax,0x4(%esp)
 57f:	8b 45 08             	mov    0x8(%ebp),%eax
 582:	89 04 24             	mov    %eax,(%esp)
 585:	e8 0a fe ff ff       	call   394 <putc>
          s++;
 58a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 58e:	eb 01                	jmp    591 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 590:	90                   	nop
 591:	8b 45 f4             	mov    -0xc(%ebp),%eax
 594:	0f b6 00             	movzbl (%eax),%eax
 597:	84 c0                	test   %al,%al
 599:	75 d7                	jne    572 <printf+0x101>
 59b:	eb 68                	jmp    605 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 59d:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 5a1:	75 1d                	jne    5c0 <printf+0x14f>
        putc(fd, *ap);
 5a3:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5a6:	8b 00                	mov    (%eax),%eax
 5a8:	0f be c0             	movsbl %al,%eax
 5ab:	89 44 24 04          	mov    %eax,0x4(%esp)
 5af:	8b 45 08             	mov    0x8(%ebp),%eax
 5b2:	89 04 24             	mov    %eax,(%esp)
 5b5:	e8 da fd ff ff       	call   394 <putc>
        ap++;
 5ba:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5be:	eb 45                	jmp    605 <printf+0x194>
      } else if(c == '%'){
 5c0:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 5c4:	75 17                	jne    5dd <printf+0x16c>
        putc(fd, c);
 5c6:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5c9:	0f be c0             	movsbl %al,%eax
 5cc:	89 44 24 04          	mov    %eax,0x4(%esp)
 5d0:	8b 45 08             	mov    0x8(%ebp),%eax
 5d3:	89 04 24             	mov    %eax,(%esp)
 5d6:	e8 b9 fd ff ff       	call   394 <putc>
 5db:	eb 28                	jmp    605 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 5dd:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 5e4:	00 
 5e5:	8b 45 08             	mov    0x8(%ebp),%eax
 5e8:	89 04 24             	mov    %eax,(%esp)
 5eb:	e8 a4 fd ff ff       	call   394 <putc>
        putc(fd, c);
 5f0:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5f3:	0f be c0             	movsbl %al,%eax
 5f6:	89 44 24 04          	mov    %eax,0x4(%esp)
 5fa:	8b 45 08             	mov    0x8(%ebp),%eax
 5fd:	89 04 24             	mov    %eax,(%esp)
 600:	e8 8f fd ff ff       	call   394 <putc>
      }
      state = 0;
 605:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 60c:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 610:	8b 55 0c             	mov    0xc(%ebp),%edx
 613:	8b 45 f0             	mov    -0x10(%ebp),%eax
 616:	01 d0                	add    %edx,%eax
 618:	0f b6 00             	movzbl (%eax),%eax
 61b:	84 c0                	test   %al,%al
 61d:	0f 85 70 fe ff ff    	jne    493 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 623:	c9                   	leave  
 624:	c3                   	ret    
 625:	66 90                	xchg   %ax,%ax
 627:	90                   	nop

00000628 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 628:	55                   	push   %ebp
 629:	89 e5                	mov    %esp,%ebp
 62b:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 62e:	8b 45 08             	mov    0x8(%ebp),%eax
 631:	83 e8 08             	sub    $0x8,%eax
 634:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 637:	a1 48 13 00 00       	mov    0x1348,%eax
 63c:	89 45 fc             	mov    %eax,-0x4(%ebp)
 63f:	eb 24                	jmp    665 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 641:	8b 45 fc             	mov    -0x4(%ebp),%eax
 644:	8b 00                	mov    (%eax),%eax
 646:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 649:	77 12                	ja     65d <free+0x35>
 64b:	8b 45 f8             	mov    -0x8(%ebp),%eax
 64e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 651:	77 24                	ja     677 <free+0x4f>
 653:	8b 45 fc             	mov    -0x4(%ebp),%eax
 656:	8b 00                	mov    (%eax),%eax
 658:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 65b:	77 1a                	ja     677 <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 65d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 660:	8b 00                	mov    (%eax),%eax
 662:	89 45 fc             	mov    %eax,-0x4(%ebp)
 665:	8b 45 f8             	mov    -0x8(%ebp),%eax
 668:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 66b:	76 d4                	jbe    641 <free+0x19>
 66d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 670:	8b 00                	mov    (%eax),%eax
 672:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 675:	76 ca                	jbe    641 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 677:	8b 45 f8             	mov    -0x8(%ebp),%eax
 67a:	8b 40 04             	mov    0x4(%eax),%eax
 67d:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 684:	8b 45 f8             	mov    -0x8(%ebp),%eax
 687:	01 c2                	add    %eax,%edx
 689:	8b 45 fc             	mov    -0x4(%ebp),%eax
 68c:	8b 00                	mov    (%eax),%eax
 68e:	39 c2                	cmp    %eax,%edx
 690:	75 24                	jne    6b6 <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 692:	8b 45 f8             	mov    -0x8(%ebp),%eax
 695:	8b 50 04             	mov    0x4(%eax),%edx
 698:	8b 45 fc             	mov    -0x4(%ebp),%eax
 69b:	8b 00                	mov    (%eax),%eax
 69d:	8b 40 04             	mov    0x4(%eax),%eax
 6a0:	01 c2                	add    %eax,%edx
 6a2:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6a5:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 6a8:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ab:	8b 00                	mov    (%eax),%eax
 6ad:	8b 10                	mov    (%eax),%edx
 6af:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6b2:	89 10                	mov    %edx,(%eax)
 6b4:	eb 0a                	jmp    6c0 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 6b6:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6b9:	8b 10                	mov    (%eax),%edx
 6bb:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6be:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 6c0:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6c3:	8b 40 04             	mov    0x4(%eax),%eax
 6c6:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 6cd:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6d0:	01 d0                	add    %edx,%eax
 6d2:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 6d5:	75 20                	jne    6f7 <free+0xcf>
    p->s.size += bp->s.size;
 6d7:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6da:	8b 50 04             	mov    0x4(%eax),%edx
 6dd:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6e0:	8b 40 04             	mov    0x4(%eax),%eax
 6e3:	01 c2                	add    %eax,%edx
 6e5:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6e8:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 6eb:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ee:	8b 10                	mov    (%eax),%edx
 6f0:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6f3:	89 10                	mov    %edx,(%eax)
 6f5:	eb 08                	jmp    6ff <free+0xd7>
  } else
    p->s.ptr = bp;
 6f7:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6fa:	8b 55 f8             	mov    -0x8(%ebp),%edx
 6fd:	89 10                	mov    %edx,(%eax)
  freep = p;
 6ff:	8b 45 fc             	mov    -0x4(%ebp),%eax
 702:	a3 48 13 00 00       	mov    %eax,0x1348
}
 707:	c9                   	leave  
 708:	c3                   	ret    

00000709 <morecore>:

static Header*
morecore(uint nu)
{
 709:	55                   	push   %ebp
 70a:	89 e5                	mov    %esp,%ebp
 70c:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 70f:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 716:	77 07                	ja     71f <morecore+0x16>
    nu = 4096;
 718:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 71f:	8b 45 08             	mov    0x8(%ebp),%eax
 722:	c1 e0 03             	shl    $0x3,%eax
 725:	89 04 24             	mov    %eax,(%esp)
 728:	e8 2f fc ff ff       	call   35c <sbrk>
 72d:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 730:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 734:	75 07                	jne    73d <morecore+0x34>
    return 0;
 736:	b8 00 00 00 00       	mov    $0x0,%eax
 73b:	eb 22                	jmp    75f <morecore+0x56>
  hp = (Header*)p;
 73d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 740:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 743:	8b 45 f0             	mov    -0x10(%ebp),%eax
 746:	8b 55 08             	mov    0x8(%ebp),%edx
 749:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 74c:	8b 45 f0             	mov    -0x10(%ebp),%eax
 74f:	83 c0 08             	add    $0x8,%eax
 752:	89 04 24             	mov    %eax,(%esp)
 755:	e8 ce fe ff ff       	call   628 <free>
  return freep;
 75a:	a1 48 13 00 00       	mov    0x1348,%eax
}
 75f:	c9                   	leave  
 760:	c3                   	ret    

00000761 <malloc>:

void*
malloc(uint nbytes)
{
 761:	55                   	push   %ebp
 762:	89 e5                	mov    %esp,%ebp
 764:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 767:	8b 45 08             	mov    0x8(%ebp),%eax
 76a:	83 c0 07             	add    $0x7,%eax
 76d:	c1 e8 03             	shr    $0x3,%eax
 770:	83 c0 01             	add    $0x1,%eax
 773:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 776:	a1 48 13 00 00       	mov    0x1348,%eax
 77b:	89 45 f0             	mov    %eax,-0x10(%ebp)
 77e:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 782:	75 23                	jne    7a7 <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 784:	c7 45 f0 40 13 00 00 	movl   $0x1340,-0x10(%ebp)
 78b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 78e:	a3 48 13 00 00       	mov    %eax,0x1348
 793:	a1 48 13 00 00       	mov    0x1348,%eax
 798:	a3 40 13 00 00       	mov    %eax,0x1340
    base.s.size = 0;
 79d:	c7 05 44 13 00 00 00 	movl   $0x0,0x1344
 7a4:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 7a7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7aa:	8b 00                	mov    (%eax),%eax
 7ac:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 7af:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7b2:	8b 40 04             	mov    0x4(%eax),%eax
 7b5:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7b8:	72 4d                	jb     807 <malloc+0xa6>
      if(p->s.size == nunits)
 7ba:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7bd:	8b 40 04             	mov    0x4(%eax),%eax
 7c0:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7c3:	75 0c                	jne    7d1 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 7c5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7c8:	8b 10                	mov    (%eax),%edx
 7ca:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7cd:	89 10                	mov    %edx,(%eax)
 7cf:	eb 26                	jmp    7f7 <malloc+0x96>
      else {
        p->s.size -= nunits;
 7d1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7d4:	8b 40 04             	mov    0x4(%eax),%eax
 7d7:	89 c2                	mov    %eax,%edx
 7d9:	2b 55 ec             	sub    -0x14(%ebp),%edx
 7dc:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7df:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 7e2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e5:	8b 40 04             	mov    0x4(%eax),%eax
 7e8:	c1 e0 03             	shl    $0x3,%eax
 7eb:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 7ee:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7f1:	8b 55 ec             	mov    -0x14(%ebp),%edx
 7f4:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 7f7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7fa:	a3 48 13 00 00       	mov    %eax,0x1348
      return (void*)(p + 1);
 7ff:	8b 45 f4             	mov    -0xc(%ebp),%eax
 802:	83 c0 08             	add    $0x8,%eax
 805:	eb 38                	jmp    83f <malloc+0xde>
    }
    if(p == freep)
 807:	a1 48 13 00 00       	mov    0x1348,%eax
 80c:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 80f:	75 1b                	jne    82c <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 811:	8b 45 ec             	mov    -0x14(%ebp),%eax
 814:	89 04 24             	mov    %eax,(%esp)
 817:	e8 ed fe ff ff       	call   709 <morecore>
 81c:	89 45 f4             	mov    %eax,-0xc(%ebp)
 81f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 823:	75 07                	jne    82c <malloc+0xcb>
        return 0;
 825:	b8 00 00 00 00       	mov    $0x0,%eax
 82a:	eb 13                	jmp    83f <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 82c:	8b 45 f4             	mov    -0xc(%ebp),%eax
 82f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 832:	8b 45 f4             	mov    -0xc(%ebp),%eax
 835:	8b 00                	mov    (%eax),%eax
 837:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 83a:	e9 70 ff ff ff       	jmp    7af <malloc+0x4e>
}
 83f:	c9                   	leave  
 840:	c3                   	ret    
 841:	66 90                	xchg   %ax,%ax
 843:	90                   	nop

00000844 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 844:	55                   	push   %ebp
 845:	89 e5                	mov    %esp,%ebp
 847:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 84a:	c7 05 60 13 00 00 00 	movl   $0x0,0x1360
 851:	00 00 00 
	STORE_ESP(ttable[0].esp);
 854:	89 e0                	mov    %esp,%eax
 856:	a3 64 13 00 00       	mov    %eax,0x1364
	STORE_EBP(ttable[0].ebp);
 85b:	89 e8                	mov    %ebp,%eax
 85d:	a3 68 13 00 00       	mov    %eax,0x1368
	ttable[0].state = T_RUNNING;
 862:	c7 05 70 13 00 00 01 	movl   $0x1,0x1370
 869:	00 00 00 
	ttable[0].wait_num = 0;
 86c:	c7 05 74 14 00 00 00 	movl   $0x0,0x1474
 873:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 876:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 87d:	eb 2c                	jmp    8ab <uthread_init+0x67>
	{
		ttable[i].tid = i;
 87f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 882:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 888:	8d 90 60 13 00 00    	lea    0x1360(%eax),%edx
 88e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 891:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 893:	8b 45 f4             	mov    -0xc(%ebp),%eax
 896:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 89c:	05 70 13 00 00       	add    $0x1370,%eax
 8a1:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 8a7:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 8ab:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 8af:	7e ce                	jle    87f <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 8b1:	c7 44 24 04 37 0b 00 	movl   $0xb37,0x4(%esp)
 8b8:	00 
 8b9:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 8c0:	e8 af fa ff ff       	call   374 <signal>
	alarm(THREAD_QUANTA);
 8c5:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 8cc:	e8 b3 fa ff ff       	call   384 <alarm>
}
 8d1:	c9                   	leave  
 8d2:	c3                   	ret    

000008d3 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 8d3:	55                   	push   %ebp
 8d4:	89 e5                	mov    %esp,%ebp
 8d6:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 8d9:	60                   	pusha  
	ticks = getTicks();
 8da:	e8 ad fa ff ff       	call   38c <getTicks>
 8df:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 8e2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 8e9:	e8 96 fa ff ff       	call   384 <alarm>
	asm("popa");
 8ee:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 8ef:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 8f6:	e9 02 01 00 00       	jmp    9fd <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 8fb:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8fe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 904:	05 70 13 00 00       	add    $0x1370,%eax
 909:	8b 00                	mov    (%eax),%eax
 90b:	85 c0                	test   %eax,%eax
 90d:	0f 85 e6 00 00 00    	jne    9f9 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 913:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 91a:	e8 42 fe ff ff       	call   761 <malloc>
 91f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 922:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 928:	81 c2 60 13 00 00    	add    $0x1360,%edx
 92e:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 931:	8b 45 f4             	mov    -0xc(%ebp),%eax
 934:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 93a:	05 60 13 00 00       	add    $0x1360,%eax
 93f:	8b 40 0c             	mov    0xc(%eax),%eax
 942:	05 00 10 00 00       	add    $0x1000,%eax
 947:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 949:	8b 45 0c             	mov    0xc(%ebp),%eax
 94c:	89 c7                	mov    %eax,%edi
 94e:	57                   	push   %edi
			PUSH(uthread_exit);
 94f:	b8 bd 0b 00 00       	mov    $0xbbd,%eax
 954:	89 c7                	mov    %eax,%edi
 956:	57                   	push   %edi
			PUSH(start_func);
 957:	8b 45 08             	mov    0x8(%ebp),%eax
 95a:	89 c7                	mov    %eax,%edi
 95c:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 95d:	b8 00 00 00 00       	mov    $0x0,%eax
 962:	89 c7                	mov    %eax,%edi
 964:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 965:	89 e0                	mov    %esp,%eax
 967:	8b 55 f4             	mov    -0xc(%ebp),%edx
 96a:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 970:	81 c2 60 13 00 00    	add    $0x1360,%edx
 976:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 979:	8b 45 f4             	mov    -0xc(%ebp),%eax
 97c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 982:	05 60 13 00 00       	add    $0x1360,%eax
 987:	8b 40 08             	mov    0x8(%eax),%eax
 98a:	8b 55 f4             	mov    -0xc(%ebp),%edx
 98d:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 993:	81 c2 60 13 00 00    	add    $0x1360,%edx
 999:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 99c:	a1 4c 13 00 00       	mov    0x134c,%eax
 9a1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9a7:	05 60 13 00 00       	add    $0x1360,%eax
 9ac:	8b 40 04             	mov    0x4(%eax),%eax
 9af:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 9b1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9b4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ba:	05 70 13 00 00       	add    $0x1370,%eax
 9bf:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 9c5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9c8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ce:	05 70 14 00 00       	add    $0x1470,%eax
 9d3:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 9da:	60                   	pusha  
			alarm(ticks);
 9db:	8b 45 f0             	mov    -0x10(%ebp),%eax
 9de:	89 04 24             	mov    %eax,(%esp)
 9e1:	e8 9e f9 ff ff       	call   384 <alarm>
			asm("popa");
 9e6:	61                   	popa   
			return ttable[i].tid;
 9e7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9ea:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9f0:	05 60 13 00 00       	add    $0x1360,%eax
 9f5:	8b 00                	mov    (%eax),%eax
 9f7:	eb 1e                	jmp    a17 <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 9f9:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 9fd:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a01:	0f 8e f4 fe ff ff    	jle    8fb <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 a07:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a0a:	89 04 24             	mov    %eax,(%esp)
 a0d:	e8 72 f9 ff ff       	call   384 <alarm>
	//failed - no free thread to use
	return -1;
 a12:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 a17:	c9                   	leave  
 a18:	c3                   	ret    

00000a19 <safe_exit>:

// task 2.4


void safe_exit()
{
 a19:	55                   	push   %ebp
 a1a:	89 e5                	mov    %esp,%ebp
 a1c:	83 ec 28             	sub    $0x28,%esp
 a1f:	eb 01                	jmp    a22 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 a21:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a22:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 a29:	eb 25                	jmp    a50 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 a2b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a2e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a34:	05 70 13 00 00       	add    $0x1370,%eax
 a39:	8b 00                	mov    (%eax),%eax
 a3b:	85 c0                	test   %eax,%eax
 a3d:	74 0d                	je     a4c <safe_exit+0x33>
				uthread_join(tid);
 a3f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a42:	89 04 24             	mov    %eax,(%esp)
 a45:	e8 1d 02 00 00       	call   c67 <uthread_join>
				break;
 a4a:	eb 0a                	jmp    a56 <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a4c:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a50:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a54:	7e d5                	jle    a2b <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 a56:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 a5a:	75 c5                	jne    a21 <safe_exit+0x8>
			exit();
 a5c:	e8 73 f8 ff ff       	call   2d4 <exit>

00000a61 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 a61:	55                   	push   %ebp
 a62:	89 e5                	mov    %esp,%ebp
 a64:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 a67:	a1 4c 13 00 00       	mov    0x134c,%eax
 a6c:	8d 50 01             	lea    0x1(%eax),%edx
 a6f:	89 d0                	mov    %edx,%eax
 a71:	c1 f8 1f             	sar    $0x1f,%eax
 a74:	c1 e8 1a             	shr    $0x1a,%eax
 a77:	01 c2                	add    %eax,%edx
 a79:	83 e2 3f             	and    $0x3f,%edx
 a7c:	89 d1                	mov    %edx,%ecx
 a7e:	29 c1                	sub    %eax,%ecx
 a80:	89 c8                	mov    %ecx,%eax
 a82:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 a85:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 a8c:	eb 20                	jmp    aae <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 a8e:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a91:	8d 50 01             	lea    0x1(%eax),%edx
 a94:	89 d0                	mov    %edx,%eax
 a96:	c1 f8 1f             	sar    $0x1f,%eax
 a99:	c1 e8 1a             	shr    $0x1a,%eax
 a9c:	01 c2                	add    %eax,%edx
 a9e:	83 e2 3f             	and    $0x3f,%edx
 aa1:	89 d1                	mov    %edx,%ecx
 aa3:	29 c1                	sub    %eax,%ecx
 aa5:	89 c8                	mov    %ecx,%eax
 aa7:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 aaa:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 aae:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ab1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ab7:	05 70 13 00 00       	add    $0x1370,%eax
 abc:	8b 00                	mov    (%eax),%eax
 abe:	83 f8 02             	cmp    $0x2,%eax
 ac1:	74 06                	je     ac9 <uthread_switch+0x68>
 ac3:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 ac7:	7e c5                	jle    a8e <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 ac9:	8b 15 4c 13 00 00    	mov    0x134c,%edx
 acf:	89 e0                	mov    %esp,%eax
 ad1:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 ad7:	81 c2 60 13 00 00    	add    $0x1360,%edx
 add:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 ae0:	8b 15 4c 13 00 00    	mov    0x134c,%edx
 ae6:	89 e8                	mov    %ebp,%eax
 ae8:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 aee:	81 c2 60 13 00 00    	add    $0x1360,%edx
 af4:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 af7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 afa:	a3 4c 13 00 00       	mov    %eax,0x134c
	LOAD_EBP(ttable[c_thread].ebp);
 aff:	a1 4c 13 00 00       	mov    0x134c,%eax
 b04:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b0a:	05 60 13 00 00       	add    $0x1360,%eax
 b0f:	8b 40 08             	mov    0x8(%eax),%eax
 b12:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 b14:	a1 4c 13 00 00       	mov    0x134c,%eax
 b19:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b1f:	05 60 13 00 00       	add    $0x1360,%eax
 b24:	8b 40 04             	mov    0x4(%eax),%eax
 b27:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 b29:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 b30:	e8 4f f8 ff ff       	call   384 <alarm>
}
 b35:	c9                   	leave  
 b36:	c3                   	ret    

00000b37 <uthread_yield>:

void uthread_yield()
{
 b37:	55                   	push   %ebp
 b38:	89 e5                	mov    %esp,%ebp
 b3a:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 b3d:	60                   	pusha  
	alarm(0);
 b3e:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 b45:	e8 3a f8 ff ff       	call   384 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 b4a:	a1 4c 13 00 00       	mov    0x134c,%eax
 b4f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b55:	05 70 13 00 00       	add    $0x1370,%eax
 b5a:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 b60:	e8 fc fe ff ff       	call   a61 <uthread_switch>
	asm("popa");
 b65:	61                   	popa   
}
 b66:	c9                   	leave  
 b67:	c3                   	ret    

00000b68 <uthread_awake>:

// task 2.5

void uthread_awake()
{
 b68:	55                   	push   %ebp
 b69:	89 e5                	mov    %esp,%ebp
 b6b:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b6e:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 b75:	eb 2c                	jmp    ba3 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 b77:	a1 4c 13 00 00       	mov    0x134c,%eax
 b7c:	6b d0 46             	imul   $0x46,%eax,%edx
 b7f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 b82:	01 d0                	add    %edx,%eax
 b84:	83 c0 04             	add    $0x4,%eax
 b87:	8b 04 85 64 13 00 00 	mov    0x1364(,%eax,4),%eax
 b8e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b94:	05 70 13 00 00       	add    $0x1370,%eax
 b99:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b9f:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 ba3:	a1 4c 13 00 00       	mov    0x134c,%eax
 ba8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bae:	05 70 14 00 00       	add    $0x1470,%eax
 bb3:	8b 40 04             	mov    0x4(%eax),%eax
 bb6:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 bb9:	7f bc                	jg     b77 <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 bbb:	c9                   	leave  
 bbc:	c3                   	ret    

00000bbd <uthread_exit>:

void uthread_exit()
{
 bbd:	55                   	push   %ebp
 bbe:	89 e5                	mov    %esp,%ebp
 bc0:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 bc3:	60                   	pusha  
	alarm(0);
 bc4:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bcb:	e8 b4 f7 ff ff       	call   384 <alarm>
	asm("popa");
 bd0:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 bd1:	a1 4c 13 00 00       	mov    0x134c,%eax
 bd6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bdc:	05 70 13 00 00       	add    $0x1370,%eax
 be1:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 be7:	a1 4c 13 00 00       	mov    0x134c,%eax
 bec:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bf2:	05 60 13 00 00       	add    $0x1360,%eax
 bf7:	8b 00                	mov    (%eax),%eax
 bf9:	85 c0                	test   %eax,%eax
 bfb:	74 1d                	je     c1a <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 bfd:	a1 4c 13 00 00       	mov    0x134c,%eax
 c02:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c08:	05 60 13 00 00       	add    $0x1360,%eax
 c0d:	8b 40 0c             	mov    0xc(%eax),%eax
 c10:	89 04 24             	mov    %eax,(%esp)
 c13:	e8 10 fa ff ff       	call   628 <free>
 c18:	eb 05                	jmp    c1f <uthread_exit+0x62>
	else
		safe_exit();
 c1a:	e8 fa fd ff ff       	call   a19 <safe_exit>
	uthread_awake();
 c1f:	e8 44 ff ff ff       	call   b68 <uthread_awake>
	uthread_switch();
 c24:	e8 38 fe ff ff       	call   a61 <uthread_switch>
	asm("popa");
 c29:	61                   	popa   
}
 c2a:	c9                   	leave  
 c2b:	c3                   	ret    

00000c2c <uthread_self>:

// task 2.6

int uthread_self()
{
 c2c:	55                   	push   %ebp
 c2d:	89 e5                	mov    %esp,%ebp
	return c_thread;
 c2f:	a1 4c 13 00 00       	mov    0x134c,%eax
}
 c34:	5d                   	pop    %ebp
 c35:	c3                   	ret    

00000c36 <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 c36:	55                   	push   %ebp
 c37:	89 e5                	mov    %esp,%ebp
 c39:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c3c:	60                   	pusha  
	alarm(0);
 c3d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c44:	e8 3b f7 ff ff       	call   384 <alarm>
	ttable[c_thread].state = T_SLEEPING;
 c49:	a1 4c 13 00 00       	mov    0x134c,%eax
 c4e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c54:	05 70 13 00 00       	add    $0x1370,%eax
 c59:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 c5f:	e8 fd fd ff ff       	call   a61 <uthread_switch>
	asm("popa");
 c64:	61                   	popa   
}
 c65:	c9                   	leave  
 c66:	c3                   	ret    

00000c67 <uthread_join>:

int uthread_join(int tid)
{
 c67:	55                   	push   %ebp
 c68:	89 e5                	mov    %esp,%ebp
 c6a:	53                   	push   %ebx
 c6b:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 c6e:	60                   	pusha  
	ticks = getTicks();
 c6f:	e8 18 f7 ff ff       	call   38c <getTicks>
 c74:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 c77:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c7e:	e8 01 f7 ff ff       	call   384 <alarm>
	asm("popa");
 c83:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 c84:	8b 45 08             	mov    0x8(%ebp),%eax
 c87:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c8d:	05 70 13 00 00       	add    $0x1370,%eax
 c92:	8b 00                	mov    (%eax),%eax
 c94:	85 c0                	test   %eax,%eax
 c96:	74 5e                	je     cf6 <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 c98:	8b 45 08             	mov    0x8(%ebp),%eax
 c9b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ca1:	05 10 01 00 00       	add    $0x110,%eax
 ca6:	05 60 13 00 00       	add    $0x1360,%eax
 cab:	8d 48 04             	lea    0x4(%eax),%ecx
 cae:	8b 45 08             	mov    0x8(%ebp),%eax
 cb1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cb7:	05 70 14 00 00       	add    $0x1470,%eax
 cbc:	8b 40 04             	mov    0x4(%eax),%eax
 cbf:	8b 15 4c 13 00 00    	mov    0x134c,%edx
 cc5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 ccb:	81 c2 60 13 00 00    	add    $0x1360,%edx
 cd1:	8b 12                	mov    (%edx),%edx
 cd3:	8b 5d 08             	mov    0x8(%ebp),%ebx
 cd6:	6b db 46             	imul   $0x46,%ebx,%ebx
 cd9:	01 c3                	add    %eax,%ebx
 cdb:	83 c3 04             	add    $0x4,%ebx
 cde:	89 14 9d 64 13 00 00 	mov    %edx,0x1364(,%ebx,4)
 ce5:	83 c0 01             	add    $0x1,%eax
 ce8:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 cea:	e8 47 ff ff ff       	call   c36 <uthread_sleep>
		return 0;
 cef:	b8 00 00 00 00       	mov    $0x0,%eax
 cf4:	eb 12                	jmp    d08 <uthread_join+0xa1>
	}
	asm("pusha");
 cf6:	60                   	pusha  
	alarm(ticks);
 cf7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 cfa:	89 04 24             	mov    %eax,(%esp)
 cfd:	e8 82 f6 ff ff       	call   384 <alarm>
	asm("popa");
 d02:	61                   	popa   
	return -1;
 d03:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 d08:	83 c4 24             	add    $0x24,%esp
 d0b:	5b                   	pop    %ebx
 d0c:	5d                   	pop    %ebp
 d0d:	c3                   	ret    

00000d0e <queue_init>:

void queue_init(struct tqueue *q)
{
 d0e:	55                   	push   %ebp
 d0f:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 d11:	8b 45 08             	mov    0x8(%ebp),%eax
 d14:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 d1b:	00 00 00 
	q->tail = 0;
 d1e:	8b 45 08             	mov    0x8(%ebp),%eax
 d21:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 d28:	00 00 00 
}
 d2b:	5d                   	pop    %ebp
 d2c:	c3                   	ret    

00000d2d <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 d2d:	55                   	push   %ebp
 d2e:	89 e5                	mov    %esp,%ebp
 d30:	57                   	push   %edi
 d31:	56                   	push   %esi
 d32:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 d33:	8b 45 08             	mov    0x8(%ebp),%eax
 d36:	8b 00                	mov    (%eax),%eax
 d38:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 d3e:	8b 45 08             	mov    0x8(%ebp),%eax
 d41:	8b 00                	mov    (%eax),%eax
 d43:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 d49:	39 c2                	cmp    %eax,%edx
 d4b:	75 07                	jne    d54 <dequeue+0x27>
		return 0;
 d4d:	b9 00 00 00 00       	mov    $0x0,%ecx
 d52:	eb 31                	jmp    d85 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 d54:	8b 45 08             	mov    0x8(%ebp),%eax
 d57:	8b 18                	mov    (%eax),%ebx
 d59:	8b 45 08             	mov    0x8(%ebp),%eax
 d5c:	8b 10                	mov    (%eax),%edx
 d5e:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 d64:	89 c1                	mov    %eax,%ecx
 d66:	c1 f9 1f             	sar    $0x1f,%ecx
 d69:	c1 e9 1a             	shr    $0x1a,%ecx
 d6c:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d6f:	83 e6 3f             	and    $0x3f,%esi
 d72:	89 f7                	mov    %esi,%edi
 d74:	29 cf                	sub    %ecx,%edi
 d76:	89 f9                	mov    %edi,%ecx
 d78:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 d7b:	83 c0 01             	add    $0x1,%eax
 d7e:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 d84:	90                   	nop
 d85:	89 c8                	mov    %ecx,%eax
}
 d87:	5b                   	pop    %ebx
 d88:	5e                   	pop    %esi
 d89:	5f                   	pop    %edi
 d8a:	5d                   	pop    %ebp
 d8b:	c3                   	ret    

00000d8c <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 d8c:	55                   	push   %ebp
 d8d:	89 e5                	mov    %esp,%ebp
 d8f:	57                   	push   %edi
 d90:	56                   	push   %esi
 d91:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 d92:	8b 45 08             	mov    0x8(%ebp),%eax
 d95:	8b 18                	mov    (%eax),%ebx
 d97:	8b 45 08             	mov    0x8(%ebp),%eax
 d9a:	8b 10                	mov    (%eax),%edx
 d9c:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 da2:	89 c1                	mov    %eax,%ecx
 da4:	c1 f9 1f             	sar    $0x1f,%ecx
 da7:	c1 e9 1a             	shr    $0x1a,%ecx
 daa:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 dad:	83 e6 3f             	and    $0x3f,%esi
 db0:	89 f7                	mov    %esi,%edi
 db2:	29 cf                	sub    %ecx,%edi
 db4:	89 f9                	mov    %edi,%ecx
 db6:	8b 35 4c 13 00 00    	mov    0x134c,%esi
 dbc:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 dc2:	81 c6 60 13 00 00    	add    $0x1360,%esi
 dc8:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 dcb:	83 c0 01             	add    $0x1,%eax
 dce:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 dd4:	5b                   	pop    %ebx
 dd5:	5e                   	pop    %esi
 dd6:	5f                   	pop    %edi
 dd7:	5d                   	pop    %ebp
 dd8:	c3                   	ret    

00000dd9 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 dd9:	55                   	push   %ebp
 dda:	89 e5                	mov    %esp,%ebp
 ddc:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 ddf:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 de6:	e8 76 f9 ff ff       	call   761 <malloc>
 deb:	8b 55 08             	mov    0x8(%ebp),%edx
 dee:	89 02                	mov    %eax,(%edx)
	if (!value)
 df0:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 df4:	75 0c                	jne    e02 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 df6:	8b 45 08             	mov    0x8(%ebp),%eax
 df9:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 e00:	eb 0a                	jmp    e0c <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 e02:	8b 45 08             	mov    0x8(%ebp),%eax
 e05:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 e0c:	c9                   	leave  
 e0d:	c3                   	ret    

00000e0e <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 e0e:	55                   	push   %ebp
 e0f:	89 e5                	mov    %esp,%ebp
 e11:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 e14:	60                   	pusha  
	ticks = getTicks();
 e15:	e8 72 f5 ff ff       	call   38c <getTicks>
 e1a:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e1d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e24:	e8 5b f5 ff ff       	call   384 <alarm>
	asm("popa");
 e29:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 e2a:	8b 45 08             	mov    0x8(%ebp),%eax
 e2d:	8b 40 04             	mov    0x4(%eax),%eax
 e30:	83 f8 01             	cmp    $0x1,%eax
 e33:	75 1c                	jne    e51 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 e35:	8b 45 08             	mov    0x8(%ebp),%eax
 e38:	89 04 24             	mov    %eax,(%esp)
 e3b:	e8 4c ff ff ff       	call   d8c <enqueue>
		uthread_sleep();
 e40:	e8 f1 fd ff ff       	call   c36 <uthread_sleep>
		alarm(0);
 e45:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e4c:	e8 33 f5 ff ff       	call   384 <alarm>
	}
	semaphore->state = S_LOCKED;
 e51:	8b 45 08             	mov    0x8(%ebp),%eax
 e54:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 e5b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e5e:	89 04 24             	mov    %eax,(%esp)
 e61:	e8 1e f5 ff ff       	call   384 <alarm>

}
 e66:	c9                   	leave  
 e67:	c3                   	ret    

00000e68 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 e68:	55                   	push   %ebp
 e69:	89 e5                	mov    %esp,%ebp
 e6b:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 e6e:	60                   	pusha  
	ticks = getTicks();
 e6f:	e8 18 f5 ff ff       	call   38c <getTicks>
 e74:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e77:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e7e:	e8 01 f5 ff ff       	call   384 <alarm>
	asm("popa");
 e83:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 e84:	8b 45 08             	mov    0x8(%ebp),%eax
 e87:	89 04 24             	mov    %eax,(%esp)
 e8a:	e8 9e fe ff ff       	call   d2d <dequeue>
 e8f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 e92:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 e96:	75 19                	jne    eb1 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 e98:	8b 45 08             	mov    0x8(%ebp),%eax
 e9b:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 ea2:	60                   	pusha  
		alarm(ticks);
 ea3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 ea6:	89 04 24             	mov    %eax,(%esp)
 ea9:	e8 d6 f4 ff ff       	call   384 <alarm>
		asm("popa");
 eae:	61                   	popa   
 eaf:	eb 0f                	jmp    ec0 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 eb1:	8b 45 f0             	mov    -0x10(%ebp),%eax
 eb4:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 ebb:	e8 77 fc ff ff       	call   b37 <uthread_yield>
	}
}
 ec0:	c9                   	leave  
 ec1:	c3                   	ret    
